<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Http\Controllers\Auth\AuthController;

use Auth;
use Gregwar\Captcha\CaptchaBuilder;

class UserController extends AuthController
{
        public function getRegister()
    {
        $req=request();
        $builder = new CaptchaBuilder;
        $builder->build();
        $imgcode=$builder->inline();
        $req->session()->put('imgcode',$builder->getPhrase());
        if ($req->ajax()) {
            return $imgcode;
        }else{
            return view('auth.register',['imgcode'=>$imgcode]);
        }
        
    }

    public function postRegister(request $request){
        $this->validate($request,
                ['imgcode'=>'required|in:'.$request->session()->get('imgcode')],
                ['imgcode.in'=>'验证码错误',
                 'imgcode.required'=>'请填写验证码'
                ]
            );
        return parent::postRegister($request);
        // if ($request->imgcode==$request->session()->get('imgcode')) {
        //     return parent::postRegister($request);
        // }else{
        //     return back();
        // }
    }


}
